package cn.edu.jsu.zjj.controller;

import cn.edu.jsu.zjj.annotation.Type;
import cn.edu.jsu.zjj.common.result.PageResult;
import cn.edu.jsu.zjj.common.result.Result;
import cn.edu.jsu.zjj.constant.MessageConstant;
import cn.edu.jsu.zjj.exception.BaseException;
import cn.edu.jsu.zjj.model.dto.docu.DocuInduceRequest;
import cn.edu.jsu.zjj.model.entity.Docu;
import cn.edu.jsu.zjj.model.entity.DocuInduce;
import cn.edu.jsu.zjj.service.DocuInduceService;
import cn.edu.jsu.zjj.service.DocuService;
import cn.edu.jsu.zjj.service.ISysDataService;
import cn.edu.jsu.zjj.service.UserService;
import cn.hutool.json.JSONObject;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/index")
@Api(tags = "资料归纳相关接口")
@Slf4j
public class IndexController {


    @Autowired
    private UserService userService;
    @Autowired
    private DocuService docuService;
    @Autowired
    private DocuInduceService docuInduceService;
    @Autowired
    private ISysDataService sysDataService;

    /**
     * 首页统计
     *
     * @return
     */
    @Type("首页统计")
    @ApiOperation("首页统计")
    @GetMapping
    public Result query() {
        JSONObject result = new JSONObject();
        // 查询教师总人数
        long teacherTotal = userService.count();
        result.set("teacherTotal", teacherTotal);

        // 查询资料总数
        long docuTotal = docuService.count();
        result.set("docuTotal", docuTotal);

        // 查询资料规范总数
        LambdaQueryWrapper<DocuInduce> induceQueryWrapper = new LambdaQueryWrapper<>();
        induceQueryWrapper.eq(DocuInduce::getIsDeleted, "0");
        long docuInduceTotal = docuInduceService.count(induceQueryWrapper);
        result.set("docuInduceTotal", docuInduceTotal);

        // 查询资料上传数量
        long docuDataTotal = sysDataService.count();
        result.set("docuDataTotal", docuDataTotal);

        // 查询待办（进行中）资料数量
        LambdaQueryWrapper<Docu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Docu::getStatus, "1");
        queryWrapper.le(Docu::getEndTime, new Date());
        long docuToDoTotal = docuService.count(queryWrapper);
        result.set("docuToDoTotal", docuToDoTotal);

        return Result.success(result);
    }

}
